package com.ls.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration //让容器管理
@EnableSwagger2 //启用swagger功能
public class SwaggerConfig {

    @Bean //将描述对象放于容器
    public Docket getDocket(){
//        Docket doc = new Docket ( DocumentationType.SWAGGER_2 )
        return new Docket(DocumentationType.SWAGGER_2)  // 指定api类型为swagger2
                .apiInfo(apiInfo())                 // 用于定义api文档汇总信息
                .select()
                //配置要扫描接口的方式,basePackage:指定要生成文档的包
                .apis( RequestHandlerSelectors
                        .basePackage("com.hs.controller"))   // 指定controller包
                .paths( PathSelectors.any())                   // 上面包下所有的controller
                .build();
    }

    //文档头部信息
    //显示到页面上的信息：可以根据公司情况填写
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder ()
                .title("OA办公系统接口文档")        // 文档页标题
                .description("OA办公系统接口文档")
                .contact(new Contact ("admin","http:localhost:8080/doc.html","xxxx@xxxx.com"))
                .version("1.0")
                .build();
    }

}
